//开发人员相关操作
import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";
import { type PaginationProps } from "@pureadmin/table";
import axios from "axios";
import { getToken, formatToken } from "@/utils/auth";
import httUrl from "@/utils/http/address";

//添加认证
axios.interceptors.request.use(config => {
  const data = getToken();
  config.headers.Authorization = formatToken(data.accessToken);
  return config;
});

/** 获取开发人员列表 */

type resultAPI = {
  isSuccess?: boolean;
  msg?: string;
  pageInfo?: object;
  result?: Array<any>;
  onePage?: PaginationProps;
  data?: string;
};

//获取表头与功能列表
export const getModeInfo = (data?: object) => {
  return http.request<resultAPI>("post", baseUrlApi("Analysis/getTableListI"), {
    data
  });
};

export const getTableListMults = (data?: object) => {
  return http.request<resultAPI>(
    "post",
    baseUrlApi("Analysis/getTableListMult"),
    {
      data
    }
  );
};

export const getListDataMults = (data?: object) => {
  return http.request<resultAPI>(
    "post",
    baseUrlApi("Analysis/getListDataMult"),
    {
      data
    }
  );
};

//获得列表数据
export const getDataLists = (data?: object) => {
  return http.request<resultAPI>("post", baseUrlApi("Analysis/getListData"), {
    data
  });
};

//获取问卷
export const getDataWenJuan = (data?: object) => {
  return http.request<resultAPI>(
    "post",
    baseUrlApi("Analysis/getListDataBySel"),
    {
      data
    }
  );
};
//提交问卷答案
export const saveWJDTDatas = (data?: object) => {
  return http.request<resultAPI>("post", baseUrlApi("Analysis/saveWJDTData"), {
    data
  });
};

//获取表单结构和表单数据
export const getFormStructAndData = (params?: object) => {
  return http.request<resultAPI>("post", baseUrlApi("Analysis/getFormData"), {
    params
  });
};

//根据APPID获取数据
export const getFormDataByAppId = (params?: object) => {
  return http.request<resultAPI>(
    "post",
    baseUrlApi("Analysis/getFormDataByAppId"),
    {
      params
    }
  );
};

//保存表单数据
export const saveDataFormd = (data?: object) => {
  return http.request<resultAPI>("post", baseUrlApi("Analysis/saveFormData"), {
    data
  });
};

//删除表单数据

export const delFormData = (params?: object) => {
  return http.request<resultAPI>("post", baseUrlApi("Analysis/delFormData"), {
    params
  });
};

//执行表单函数

export const exeFormFunApi = (data?: object) => {
  return http.request<resultAPI>(
    "post",
    baseUrlApi("Analysis/exeFormFunction"),
    {
      data
    }
  );
};

//导入Excel数据
export const importData = (data?: object) => {
  return axios
    .post(httUrl + "/api/Analysis/ImportExcel", data)
    .then(function (res) {
      //console.log(res);
      return res.data;
    });
};

//导入特殊的Excel数据
export const importExlData = (data?: object) => {
  return axios
    .post(httUrl + "/api/Analysis/ImportExcelEx", data)
    .then(function (res) {
      //console.log(res);
      return res.data;
    });
};

//导出Excel数据
export const excelData = (data?: object) => {
  return http.request<resultAPI>("post", baseUrlApi("Analysis/ExportExcel"), {
    data
  });
};

//获取健值对表，健的集合数据
export const getKeyTableList = (params?: object) => {
  return http.request<resultAPI>(
    "post",
    baseUrlApi("Analysis/getFunContrlTable"),
    {
      params
    }
  );
};

//权限调用接口
export const getRolesList = (params?: object) => {
  return http.request<resultAPI>("get", baseUrlApi("Application/getMultiple"), {
    params
  });
};
